<template>
    <div class='addExpress'>
        <el-dialog 
            title="快递信息" 
            :before-close="handleClose"
            :visible.sync="expressDialogVisible" width="30%">
        
        <el-form ref="form" label-width="100px">
          <el-form-item label="快递公司">
              <el-input v-model="form.servicesCompany" placeholder="请输入快递公司"></el-input>
          </el-form-item>
          <el-form-item label="快递单号">
              <el-input v-model="form.recommenderId" placeholder="请输入快递单号"></el-input>
          </el-form-item>

        </el-form>    
        <span slot="footer" class="dialog-footer">
          <el-button @click="expressDialogVisible = false">取 消</el-button>
          <el-button type="primary" @click="sureExpress()">确 定</el-button>
        </span>
      </el-dialog>
    </div>
</template>



<script>
import { ajax } from "@/api";
import { getToken } from "@/utils/auth";
export default {
    name:'addExpress',
    data(){
        return {
            expressDialogVisible:false,
            form:{
                servicesCompany:'',
                recommenderId:''
            },
            orderExpressParams:{    //订单快递提交
                orderId:'',
                expressName:'',
                expressNumber:'',
                token:getToken()
            },
        }
    },
    methods:{
        handleClose(done) {
            done();
        },
        openAddExpress(id){
            this.expressDialogVisible = true;
            this.orderExpressParams.orderId = id;
        },

        //填写快递信息  - 订单快递提交
        sureExpress(){
            if(this.form.servicesCompany === ''){
            return this.$message.error('请输入物流名称');
            }
            if(this.form.recommenderId === ''){
            return this.$message.error('请输入物流单号');
            }
            this.orderExpressParams.expressName = this.form.servicesCompany;
            this.orderExpressParams.expressNumber = this.form.recommenderId;
            ajax('orderExpress',this.orderExpressParams).then((res) => {
            if(res.data.status){
                this.$message.success('订单快递提交成功');
                this.expressDialogVisible = false;
                setTimeout(() => {
                    location.reload();
                },100);
                // location.reload();
            }else{
                this.$message.error(json.message);
            }
            });
        },

    }
}
</script>


<style lang="less" scoped>
.addExpress{

}
</style>
